import re
def check(s):
    flag=True
    if re.search('[a-z]',s):
        print('invalid input')
        flag=False
    return flag
def format(s):
    s = s.replace(' ', '')
    s = s.replace('--','+')
    s = s.replace('+-','-')
    return s
def count_chengchu(s):
    x,y=re.split('[*/]',s)
    if re.search('\*',s):
        s=float(x)*float(y)
    else:
        s=float(x)/float(y)
    return s
def count_jiajian(s):
    [x,y] = re.findall('-?\d+\.?\d*',s)
    s=float(x)+float(y)
    return s
exit_flag=False
while not exit_flag:
    num = input('please input count_num[quit:Q]>>')
    if num == 'Q':
        print('thanks')
        exit_flag=True
    elif check(num):
        count_end = False
        while not count_end:
            num=format(num)
            if re.search('\([^()]+\)', num):
                count1 = re.search('\([^()]+\)', num).group()
                if re.search('-?\d+\.?\d*[/*]-?\d+\.?\d*', count1):
                    count2 = re.search('-?\d+\.?\d*[/*]-?\d+\.?\d*', count1).group()
                    count3 = count_chengchu(count2)
                    num = num.replace(count2, str(count3))
                elif re.search('-?\d+\.?\d*[-+]-?\d+\.?\d*', count1):
                    count2 = re.search('-?\d+\.?\d*[-+]-?\d+\.?\d*', count1).group()
                    count3 = count_jiajian(count2)
                    num = num.replace(count2, str(count3))
                else:
                    ret1 = re.search('-?\d+\.?\d*', count1).group()
                    num = num.replace(count1, ret1)
            else:
                if re.search('-?\d+\.?\d*[/*]-?\d+\.?\d*', num):
                    count2 = re.search('-?\d+\.?\d*[/*]-?\d+\.?\d*', num).group()
                    count3 = count_chengchu(count2)
                    num = num.replace(count2, str(count3))
                elif re.search('-?\d+\.?\d*[-+]-?\d+\.?\d*', num):
                    count2 = re.search('-?\d+\.?\d*[-+]-?\d+\.?\d*', num).group()
                    count3 = count_jiajian(count2)
                    num = num.replace(count2, str(count3))
                print(num)
                count_end=True
